class Solution {
public:
    int cnt = 0;
    int st[2010] = { 0 };
    bool is_ok()
    {
        int cnt1 = 0;
        for (int i = 1; i <= 2000; i++) {
            cnt1 += (st[i] >= 1);
        }
        return cnt1 == cnt;
    }
    int countCompleteSubarrays(vector<int>& nums) {
        map<int, int>mp;
        for (auto x : nums) {
            if (!mp[x]) {
                mp[x] = 1;
                cnt++;
            }
        }
        if (cnt == 1) {
            int n = nums.size();
            return n * (n + 1) / 2;
            // 1+2+3+4
        }
        int j = 0;
        int ans = 0;
        bool flag = 0;
        for (int i = 0; i < nums.size(); i++) {
            int x = nums[i];
            st[x]++;
            if (is_ok() && !flag) {
                //cout<<"ans=="<<(nums.size()-i)<<endl;
                flag = 1;
                ans += (nums.size() - i);
                st[nums[j]]--;
                j++;
                //cout<<"ans=="<<ans<<endl;
            }
            bool flag1 = 0;
            while (is_ok()) {
                //cout<<"j=="<<j<<endl;
                //cout<<"i=="<<i<<endl;
                //ans++;
                //ans+=
                ans += (nums.size() - i);
                st[nums[j]]--;
                j++;

                //ans+=(nums.size()-j);
                // if(!flag){
                //     flag=1;
                //     continue;
                // }
                // else ans++;
            }
        }
        return ans;
    }
};